package com.zm.exam.springbootexam.biz;

import com.zm.exam.springbootexam.entry.Paper;
import com.zm.exam.springbootexam.entry.PaperDetail;
import com.zm.exam.springbootexam.mapper.PaperDetailMapper;
import com.zm.exam.springbootexam.mapper.PaperMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PaperBiz {
    @Autowired
    PaperMapper paperMapper;
    @Autowired
    PaperDetailMapper paperDetailMapper;

    @Transactional(rollbackFor = BizException.class)
    public void create(Paper paper) throws BizException {
        //TODO考卷同名验证
        paperMapper.insert(paper);
        for (PaperDetail detail : paper.getDetails()) {
            detail.setPid(paper.getId());
            paperDetailMapper.insert(detail);
        }
    }
}
